Skip to content

Conversation

@mikehostetler
Copy link
Contributor

Problem

OpenAI and xAI only support image attachments via their Chat Completions API. Non-image files (PDFs, etc.) fail with cryptic API errors.

Solution

  • Add upfront validation in OpenAI and xAI providers to detect non-image file attachments
  • Return clear, actionable error messages suggesting Anthropic or Google for document support
  • Document attachment support matrix in provider guides

Changes

  • lib/req_llm/provider/defaults.ex: Add validate_image_only_attachments/1 helper
  • lib/req_llm/providers/openai.ex: Validate attachments in prepare_request(:chat, ...)
  • lib/req_llm/providers/xai.ex: Validate attachments in prepare_chat_request/3
  • guides/openai.md: Document attachment limitations
  • guides/xai.md: Document attachment limitations
  • Tests for both providers verifying image acceptance and clear error messages for non-images

Closes #317

Adds upfront validation to detect non-image file attachments and return
helpful error messages before making API calls. Documents the attachment
support matrix in provider guides.

Closes #317

Amp-Thread-ID: https://ampcode.com/threads/T-019c117b-7aa8-72ba-9556-23dc1118034f
Co-authored-by: Amp <[email protected]>
@mikehostetler mikehostetler force-pushed the fix/317-attachment-validation branch from 48ca056 to 47314af Compare January 31, 2026 01:25
@mikehostetler mikehostetler merged commit 00ba776 into main Jan 31, 2026
6 checks passed
@mikehostetler mikehostetler deleted the fix/317-attachment-validation branch January 31, 2026 01:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: OpenAI, xAI don't encode non-image attachments properly

2 participants